{extend name="base"/}
{block name="resources"}
<link rel="stylesheet" href="SHOP_CSS/goods_lists.css">
<style>
    .export-record{margin-left:20px;}
	.promotion-addon span {
		border-radius: 3px;
		border: 1px solid;
		font-size: 12px;
		line-height: 14px;
		padding: 2px 4px;
		margin-right: 3px;
		margin-top: 3px;
		color: #FFFFFF;
	}
	.btn-color{
		color:#FF6A00;
		cursor: pointer;
	}
	.btn-color:hover{
		color:#FF6A00;
	}
	.info-wrap{
		width: 100%;
	}
	.prices {

		width: 100%;
	}
	.vips_price{
		cursor: pointer;
	}
</style>
{/block}
{block name="main"}
<!--<div class="ns-tips layui-collapse">
	<div class="layui-colla-item">
		<h2 class="layui-colla-title">操作提示</h2>
		<ul class="layui-colla-content layui-show">
			<li>当前显示的是已经审核通过的商品</li>
			<li>如果商家的商品操作违规，平台可以操作违规下架，违规下架的商品需要商家编辑审核之后才能重新上架</li>
		</ul>
	</div>
</div>-->
<!-- 按钮容器 -->
<div class="ns-single-filter-box" style="justify-content:unset;">
	<button class="layui-btn ns-bg-color" onclick="add()">添加商品</button>
	{if $goodsgrab_is_exit}<button class="layui-btn ns-bg-color" onclick="grab()">商品采集</button>{/if}
</div>

<!-- 筛选面板 -->
<div class="ns-screen layui-collapse" lay-filter="selection_panel">
	<div class="layui-colla-item">
		<h2 class="layui-colla-title"></h2>
		<form class="layui-colla-content layui-form layui-show">
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">商品名称：</label>
					<div class="layui-input-inline">
						<input type="text" name="search_text" placeholder="请输入商品名称" autocomplete="off" class="layui-input">
					</div>
				</div>

				<div class="layui-inline">
					<label class="layui-form-label">商品分类：</label>
					<div class="layui-input-inline">
						{include file="goods/category_select" /}
					</div>
				</div>
				<!--<div class="layui-inline">
					<label class="layui-form-label">店内分类：</label>
					<div class="layui-input-inline">
						<select name="goods_shop_category_ids" lay-filter="goods_shop_category_ids">
							<option value="0" data-level="0">顶级分类</option>
							{foreach name="$goods_shop_category_list" item="vo"}
							<option value="{$vo['category_id']}" data-level="{$vo['level']}">{$vo['category_name']}</option>
								{notempty name="$vo['child_list']"}
								{foreach name="$vo['child_list']" item="vo_child"}
								<option value="{$vo_child['category_id']}" data-level="{$vo_child['level']}">&nbsp;&nbsp;&nbsp;&nbsp;{$vo_child['category_name']}</option>
								{/foreach}
								{/notempty}
							{/foreach}
						</select>
					</div>
				</div>-->
				
			</div>
			<!--<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">销量：</label>
					<div class="layui-input-inline">
						<input type="number" name="start_sale" id="start_sale" lay-verify="int" placeholder="最低销量" class="layui-input" autocomplete="off">
					</div>
					<div class="layui-form-mid">-</div>
					<div class="layui-input-inline">
						<input type="number" name="end_sale" id="end_sale" lay-verify="int" placeholder="最高销量" class="layui-input" autocomplete="off">
					</div>
				</div>
			</div>-->
			
			<!--<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">商品类型：</label>
					<div class="layui-input-inline">
						<select name="goods_class" lay-filter="goods_class">
							<option value="">全部</option>
							<option value="1">实物商品</option>
							<option value="2">虚拟商品</option>
						</select>
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">营销活动：</label>
					<div class="layui-input-inline">
						<select name="promotion_type" lay-filter="promotion_type">
							<option value="">全部</option>
							{foreach name="$promotion_type" item="vo"}
							<option value="{$vo['type']}">{$vo['name']}</option>
							{/foreach}
						</select>
					</div>
				</div>
			</div>-->

			<input type="hidden" name="goods_state" />
			<input type="hidden" name="verify_state" />
			<div class="ns-form-row">
				<button class="layui-btn ns-bg-color" lay-submit lay-filter="search">筛选</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
<!--				<button class="layui-btn ns-bg-color" lay-submit lay-filter="export">导出商品</button>-->
<!--                <a class='layui-btn layui-btn-primary' href='{:addon_url("shop/goods/export")}' target="_blank">商品导出记录</a>-->
			</div>
		</form>
	</div>
</div>

<div class="layui-tab ns-table-tab" lay-filter="goods_list_tab">
	<ul class="layui-tab-title">
		<li class="layui-this" lay-id="">全部</li>
		<li lay-id="1" data-type="goods_state">销售中</li>
		<li lay-id="0" data-type="goods_state">仓库中</li>
		<!--{foreach name="$verify_state" item="vo" key="k"}
		<li lay-id="{$vo['state']}" data-type="verify_state">
			<div>{$vo['value']}{if $vo['count']>0}<span>(</span><span class="count">{$vo['count']}</span><span>)</span>{/if}</div>
		</li>
		{/foreach}-->
	</ul>
	<div class="layui-tab-content">
		<table id="goods_list" lay-filter="goods_list"></table>
	</div>
</div>

<!-- 商品信息 -->
<script type="text/html" id="goods_info">
	<div class="ns-table-title">
		<div class="contraction" data-goods-id="{{d.goods_id}}" data-open="0">
			<span>+</span>
		</div>
<!--		{{d.promotion_addon}}-->
<!--		{{d.promotion_addon_list}}-->
		<div class="ns-title-pic" id="goods_img_{{d.goods_id}}">
			<img layer-src="{{ns.img(d.goods_image.split(',')[0], 'big')}}" src="{{ns.img(d.goods_image.split(',')[0], 'small')}}"/>
		</div>

		<div class="ns-title-content">
			<a href="javascript:;" class="ns-multi-line-hiding ns-gn-color" title="{{d.goods_name}}" lay-event="preview">{{d.goods_name}}</a>
			{{# if(d.promotion_addon && d.promotion_addon_list){ }}
			<div class="promotion-addon">
				{{# for(var i=0;i<d.promotion_addon_list.length;i++){ }}
				<a href="{{
				if(inArray('shop_url',d.promotion_addon_list[i]){
					ns.url( d.promotion_addon_list[i].shop_url)
				}else{
					ns.url( d.promotion_addon_list[i].url)
				}
				}}"><span class="ns-bg-color" title="{{d.promotion_addon_list[i].name}}">{{ d.promotion_addon_list[i].short }}</span></a>
				{{# } }}
			</div>
			{{# } }}
			{{# if(d.is_consume_discount ==1){ }}
			<!--<span class="promotion-addon vips_price" data-goods-id="{{d.goods_id}}" data-open="0">
				<span class="layui-bg-black " title="会员价"><span class="iconfont iconhuiyuan icon"> 会员价</span></span>
			</span>-->

			{{# } }}
		</div>
	</div>
</script>

<!-- 操作 -->
<script type="text/html" id="action">
	<div class="operation-wrap" data-goods-id="{{d.goods_id}}">
		<div class="popup-qrcode-wrap"><img class="popup-qrcode-loadimg" src="__STATIC__/loading/loading.gif" /></div>
		<div class="ns-table-btn">
			{{# if(d.verify_state == 1 && d.goods_state == 1){ }}
<!--			<a class="layui-btn" lay-event="select">推广</a>-->
			<a class="layui-btn" lay-event="edit">编辑</a>
			<a class="layui-btn" lay-event="delete">删除</a>
			<a class="layui-btn" lay-event="off_goods">下架</a>
			{{# } else if(d.verify_state == 1 && d.goods_state == 0){ }}
<!--			<a class="layui-btn" lay-event="select">推广</a>-->
			<a class="layui-btn" lay-event="edit">编辑</a>
			<a class="layui-btn" lay-event="delete">删除</a>
			<a class="layui-btn" lay-event="on_goods">上架</a>
			{{# } else if(d.verify_state == 0){ }}
			<a class="layui-btn" lay-event="edit">编辑</a>
			<a class="layui-btn" lay-event="delete">删除</a>
			{{# }else{ }}
			<a class="layui-btn" lay-event="edit">编辑</a>
			<a class="layui-btn" lay-event="delete">删除</a>
			{{# } }}
<!--			<a class="layui-btn" lay-event="copy">复制</a>-->
<!--			<a class="layui-btn" lay-event="member_price">会员价</a>-->
<!--			<a class="layui-btn" lay-event="browse_records">浏览记录</a>-->
		</div>
	</div>
</script>
<!-- 批量操作 -->
<script type="text/html" id="toolbarOperation">
	<button class="layui-btn layui-btn-primary" lay-event="on_goods">批量上架</button>
	<button class="layui-btn layui-btn-primary" lay-event="off_goods">批量下架</button>
<!--	<button class="layui-btn layui-btn-primary" lay-event="delete">批量删除</button>-->
<!--	<button class="layui-btn layui-btn-primary" lay-event="batch_set">批量设置</button>-->
</script>
<!-- 批量操作 -->
<script type="text/html" id="batchOperation">
	<button class="layui-btn layui-btn-primary" lay-event="on_goods">批量上架</button>
	<button class="layui-btn layui-btn-primary" lay-event="off_goods">批量下架</button>
<!--	<button class="layui-btn layui-btn-primary" lay-event="delete">批量删除</button>-->
<!--	<button class="layui-btn layui-btn-primary" lay-event="batch_set">批量设置</button>-->
</script>

<!-- SKU商品列表 -->
<script type="text/html" id="skuList">
	<tr class="js-sku-list-{{d.index}}" id="sku_img_{{d.index}}">
		<td></td>
		<td colspan="7">
			<ul class="sku-list">
				{{# for(var i=0;i<d.list.length;i++){ }}
				<li>
					<div class="img-wrap">
						<img layer-src="{{ns.img(d.list[i].sku_image, 'big')}}" src="{{ns.img(d.list[i].sku_image, 'small')}}">
					</div>
					<div class="info-wrap">
						<span class="sku-name">{{d.list[i].sku_name}}</span>
<!--						<span class="price">价格：￥{{d.list[i].price}}</span>-->
						<span class="stock">库存：{{d.list[i].stock}}</span>
						<span class="sale_num">销量：{{d.list[i].sale_num}}</span>
						<div class="prices">
							价格: ￥{{d.list[i].price}}
							{{# if (d.list[i].member_price_list) { }}
							{{#  layui.each(d.list[i].member_price_list, function(index, item){ }}
							<p class="vip_price">{{ item.level_name }} ￥{{ item.member_price }}</p>
							{{#  }); }}
							{{#  } }}
						</div>
					</div>
				</li>
				{{# } }}
			</ul>
		</td>
	</tr>
</script>

<!-- 商品推广 -->
<script type="text/html" id="goods_url">
	{{# if(d.path.h5.status == 1){ }}
	<img src="{{ ns.img(d.path.h5.img) }}" alt="推广二维码">
	<p class="qrcode-item-description">扫码后直接访问商品</p>
	<a class="ns-text-color" href="javascript:ns.copy('h5_url_{{ d.goods_id }}');">复制链接</a>
	<a class="ns-text-color" href="{{ ns.img(d.path.h5.img) }}" download>下载二维码</a>
	<input class="layui-input nc-len-mid" type="text" value="{{ d.path.h5.url }}" id="h5_url_{{ d.goods_id }}" readonly>
	{{# } }}
</script>

<!-- 商品预览 -->
<script type="text/html" id="goods_preview">
	<div class="goods-preview">
		<div class="qrcode-wrap">
			<img src="{{ ns.img(d.path.h5.img) }}" alt="推广二维码">
			<p class="tips ns-text-color">手机扫码购买</p>
		</div>
		<div class="phone-wrap">
			<div class="iframe-wrap">
				<iframe src="{{ d.path.h5.url }}&preview=1" frameborder="0"></iframe>
			</div>
		</div>
	</div>
</script>

{/block}

{block name="script"}
<!-- 编辑库存html -->
<script type="text/html" id="edit_stock">
	<div class="layui-form" id="edit_stock_block" lay-filter="form">
		<table class="layui-table" lay-skin="line">
			<colgroup>
				<col width="16%">
				<col width="12%">
				<col width="12%">
				<col width="12%">
				<col width="12%">
				<col width="12%">
				<col width="12%">
				<col width="12%">
			</colgroup>
			<thead>
				<tr>
					<th>sku名称</th>
					<th>销售价</th>
					<th>划线价</th>
					<th>成本价</th>
					<th>库存</th>
					<th>重量(kg)</th>
					<th>体积(m³)</th>
					<th>sku编码</th>
				</tr> 
			</thead>
			<tbody>
				{{#  layui.each(d, function(index, item){ }}
				<tr>
					<td><input type="hidden" name="sku_list[{{index}}][sku_id]" value="{{ item.sku_id }}" class="layui-input">{{ item.sku_name }}</td>
					<td><input type="number" name="sku_list[{{index}}][price]" value="{{ item.price }}" class="layui-input" lay-verify="flo"></td>
					<td><input type="number" name="sku_list[{{index}}][market_price]" value="{{ item.market_price }}" class="layui-input" lay-verify="flo"></td>
					<td><input type="number" name="sku_list[{{index}}][cost_price]" value="{{ item.cost_price }}" class="layui-input" lay-verify="flo"></td>
					<td><input type="number" name="sku_list[{{index}}][stock]" value="{{ item.stock }}" class="layui-input" lay-verify="int"></td>
					<td><input type="number" name="sku_list[{{index}}][weight]" value="{{ item.weight }}" class="layui-input" lay-verify="flo"></td>
					<td><input type="number" name="sku_list[{{index}}][volume]" value="{{ item.volume }}" class="layui-input" lay-verify="flo"></td>
					<td><input type="text" name="sku_list[{{index}}][sku_no]" value="{{ item.sku_no }}" class="layui-input"></td>
				</tr>
				{{#  }); }}
			</tbody>
		</table>
		
		<div class="ns-form-row">
			<button class="layui-btn ns-bg-color" lay-submit lay-filter="edit_stock">确定</button>
			<button class="layui-btn layui-btn-primary" onclick="closeStock()">返回</button>
		</div>
	</div>
</script>

<!-- 批量操作 -->
<script type="text/html" id="batchSet">
	<div class="batch-set-wrap">
		<div class="tips">每次仅能设置一项，点击保存成功之后生效</div>
		<div class="set-wrap">
			<div class="tab-wrap">
				<ul>
					<li class="active" data-type="category">分类</li>
					<li data-type="shop_category">店内分类</li>
					<li data-type="limit">起售 / 限购</li>
					<li data-type="shipping">包邮设置</li>
				</ul>
			</div>
			<div class="content-wrap">
				<div class="tab-item tab-show category">
					<div class="layui-form">
						<div class="layui-form-item">
							<label class="layui-form-label">分类：</label>
							<div class="layui-input-block">
								<div class="layui-input-inline">
									<select name="batch_category">
										<option value="0">请选择分类</option>
										{foreach $category_list as $category_k => $category_v}
											<option value="{$category_v['category_id']}"  data-level="{$category_v['level']}" >{$category_v['category_name']}</option>
											{notempty name="$category_v['child_list']"}
												{foreach name="$category_v['child_list']" item="second_child"}
													<option value="{$second_child['category_id']}" data-level="{$second_child['level']}">&nbsp;&nbsp;&nbsp;&nbsp;{$second_child['category_name']}</option>
													{notempty name="$second_child['child_list']"}
														{foreach name="$second_child['child_list']" item="third_child"}
															<option value="{$third_child['category_id']}" data-level="{$third_child['level']}">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$third_child['category_name']}</option>
														{/foreach}
													{/notempty}
											{/foreach}
											{/notempty}
										{/foreach}
									</select>
								</div>
							</div>
						</div>
					</div>
				</div>
				<div class="tab-item shop_category">
					<div class="layui-form">
						<div class="layui-form-item ">
							<label class="layui-form-label">店内分类：</label>
							<div class="layui-input-block">
								<div class="layui-input-inline js-goods-shop-category"></div>
								<button class="layui-btn layui-btn-primary add_shop_category">添加</button>
							</div>
						</div>
					</div>
				</div>

				<div class="tab-item limit">
					<div class="layui-form">
						<div class="layui-form-item">
							<label class="layui-form-label">商品限购：</label>
							<div class="layui-input-block">
								<input type="number" name="batch_max_buy" value="0" lay-verify="max_buy" class="layui-input ns-len-short" autocomplete="off">
								<div class="layui-form-mid">/件</div>
							</div>
							<div class="ns-word-aux">该限购为终身限购，0为不限购</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">商品起售：</label>
							<div class="layui-input-block">
								<input type="number" name="batch_min_buy" value="0" lay-verify="min_buy" class="layui-input ns-len-short" autocomplete="off">
								<div class="layui-form-mid">/件</div>
							</div>
							<div class="ns-word-aux">起售数量超出商品库存时，买家无法购买该商品</div>
						</div>
					</div>
				</div>

				<div class="tab-item shipping">
					<div class="layui-form">
						<div class="layui-form-item">
							<label class="layui-form-label">是否包邮：</label>
							<div class="layui-input-block">
								<div class="layui-input-inline">
									<input type="radio" name="is_free_shipping" value="1" title="是" checked>
									<input type="radio" name="is_free_shipping" value="0" title="否">
								</div>
							</div>
						</div>
						<div class="layui-form-item shipping_template" style="display:none;">
							<label class="layui-form-label">运费模板：</label>
							<div class="layui-input-block">
								<div class="layui-input-inline">
									<select name="batch_shipping_template" lay-search="">
										<option value="0">请选择运费模板</option>
										{foreach name="$express_template_list" item="vo"}
										<option value="{$vo['template_id']}">{$vo['template_name']}</option>
										{/foreach}
									</select>
								</div>
							</div>
						</div>
						<div class="ns-word-aux">该设置仅对实物商品有效</div>
					</div>
				</div>

				<div class="tab-item result">
					<img src="SHOP_IMG/success.png">
					<div class="text">设置成功</div>
				</div>
			</div>
		</div>
		<div class="footer-wrap">
			<button class="layui-btn layui-btn-primary" onclick="layer.closeAll()">取消</button>
			<button class="layui-btn ns-bg-color" onclick="batchSetting()">保存</button>
		</div>
	</div>
</script>

<!--店内分类-->
<script type="text/html" id="shop_category_html">
	<div class="item">
		<select class='shop_category_class' name="batch_shop_category[]" lay-search=""  lay-filter="batch_shop_category">
			<option value="0">请选择店内分类</option>
			{foreach $goods_shop_category_list as $shop_k => $shop_v}
				<option value="{$shop_v['category_id']}"  data-level="{$shop_v['level']}" >{$shop_v['category_name']}</option>
				{notempty name="$shop_v['child_list']"}
					{foreach name="$shop_v['child_list']" item="vo_child"}
					<option value="{$vo_child['category_id']}" data-level="{$vo_child['level']}">&nbsp;&nbsp;&nbsp;&nbsp;{$vo_child['category_name']}</option>
					{/foreach}
				{/notempty}
			{/foreach}
		</select>
		<i class="layui-icon layui-icon-close"></i>
	</div>
</script>
<script>
	var member_price_is_exit;
	member_price_is_exit = "{$memberprice_is_exit}";
</script>
<script src="SHOP_JS/goods_edit_category.js"></script>
<script src="SHOP_JS/goods_list.js"></script>
{/block}
